package com.example.aircraft.aircraft;


import android.util.Log;

import com.example.aircraft.ImageManager;
import com.example.aircraft.MyApplication;

//敌机工厂类
public class EnemyFactory {
    private final double ene_thr = 0.5;
    private int boss_thr=0;
    private int score_thr = 1000;
    public static boolean bossInsist = false;
    private FactoryBase factory;
    /**
     * 设置敌机工厂参数
     */
    public EnemyFactory(int level){
        switch(level){
            case 1:factory = new EasyFactory();
                    break;
            case 2:factory = new NormFactory();
                    break;
            case 3:factory = new HardFactory();
                    break;
            default:break;
        }
    }
    public Enemy setEnemy(int Score){
        return factory.setEnemy(Score);
    }
}
abstract class FactoryBase{
    protected double ene_thr;
    protected int boss_thr=0;
    protected int score_thr=0;
    protected boolean bossInsist = false;
    //Hp参数
    protected int hpParam;
    //移动速度参数
    protected int speedParam=0;
    public abstract Enemy setEnemy(int score);
}
class EasyFactory extends FactoryBase{
    public EasyFactory(){
        hpParam = 30;
        ene_thr = 0.9;
    }
    @Override
    public Enemy setEnemy(int score) {
        double seed = Math.random();
        int Direct = (int)Math.pow(-1,(int)(seed*10));

        if(seed>=ene_thr){
            return new EliteEnemy((int) ( Math.random() * (MyApplication.getContext().getResources().getDisplayMetrics().widthPixels - ImageManager.ELITE_ENEMY_IMAGE.getWidth()))*1,
                    (int) (Math.random() *MyApplication.getContext().getResources().getDisplayMetrics().heightPixels * 0.2)*1,
                    Direct*4,
                    15,
                    hpParam*2);
        }else if(seed<ene_thr){
            return new MobEnemy((int) ( Math.random() * (MyApplication.getContext().getResources().getDisplayMetrics().widthPixels - ImageManager.MOB_ENEMY_IMAGE.getWidth()))*1,
                    (int) (Math.random() * MyApplication.getContext().getResources().getDisplayMetrics().heightPixels * 0.2)*1,
                    0,
                    10,
                    hpParam);
        }
        return null;
    }
}
class NormFactory extends FactoryBase{
    private int inithpParam;
    public NormFactory(){
        ene_thr = 0.5;
        score_thr=1500;
        //Hp参数
        hpParam = 30;
        inithpParam = hpParam;

    }
    @Override
    public Enemy setEnemy(int score) {
        int boss_thr_t = score/score_thr;
        double seed = Math.random();
        int Direct = (int)Math.pow(-1,(int)(seed*10));
        ene_thr-=0.01;
//        System.out.println("==>精英敌机出现概率增加<==");
        if(boss_thr_t>boss_thr && !bossInsist){
            speedParam += 2;
            hpParam+=5;
            boss_thr=boss_thr_t;
            bossInsist = true;
            return new BossEnemy((int) ( Math.random() * (MyApplication.getContext().getResources().getDisplayMetrics().widthPixels - ImageManager.BOSS_ENEMY_IMAGE.getWidth()))*1,
                    (int) (Math.random() * MyApplication.getContext().getResources().getDisplayMetrics().heightPixels * 0.2)*1,
                    5+speedParam,
                    0,
                    inithpParam*10);
        }else if(seed>=ene_thr){
            return new EliteEnemy((int) ( Math.random() * (MyApplication.getContext().getResources().getDisplayMetrics().widthPixels - ImageManager.ELITE_ENEMY_IMAGE.getWidth()))*1,
                    (int) (Math.random() * MyApplication.getContext().getResources().getDisplayMetrics().heightPixels * 0.2)*1,
                    Direct*2+speedParam,
                    15+speedParam,
                    hpParam*2);
        }else if(seed<ene_thr){
            return new MobEnemy((int) ( Math.random() * (MyApplication.getContext().getResources().getDisplayMetrics().widthPixels - ImageManager.MOB_ENEMY_IMAGE.getWidth()))*1,
                    (int) (Math.random() * MyApplication.getContext().getResources().getDisplayMetrics().heightPixels * 0.2)*1,
                    0,
                    10+speedParam,
                    hpParam);
        }
        return null;
    }
}
class HardFactory extends FactoryBase{
    public HardFactory(){
        ene_thr = 0.5;
        score_thr=1000;
        //Hp参数
        hpParam = 30;
    }
    @Override
    public Enemy setEnemy(int score) {
        int boss_thr_t = score/score_thr;
        double seed = Math.random();
        int Direct = (int)Math.pow(-1,(int)(seed*10));
        ene_thr-=0.02;
//        System.out.println("==>精英敌机出现概率增加<==");
        if(boss_thr_t>boss_thr && !bossInsist){
            speedParam += 5;
            hpParam+=10;
            boss_thr=boss_thr_t;
            bossInsist = true;
            return new BossEnemy((int) ( Math.random() * (MyApplication.getContext().getResources().getDisplayMetrics().widthPixels - ImageManager.BOSS_ENEMY_IMAGE.getWidth()))*1,
                    (int) (Math.random() * MyApplication.getContext().getResources().getDisplayMetrics().heightPixels * 0.2)*1,
                    5+speedParam,
                    0,
                    hpParam*10);
        }else if(seed>=ene_thr){
            return new EliteEnemy((int) ( Math.random() * (MyApplication.getContext().getResources().getDisplayMetrics().widthPixels - ImageManager.ELITE_ENEMY_IMAGE.getWidth()))*1,
                    (int) (Math.random() * MyApplication.getContext().getResources().getDisplayMetrics().heightPixels * 0.2)*1,
                    Direct*2+speedParam,
                    15+speedParam,
                    hpParam*2);
        }else if(seed<ene_thr){
            return new MobEnemy((int) ( Math.random() * (MyApplication.getContext().getResources().getDisplayMetrics().widthPixels - ImageManager.MOB_ENEMY_IMAGE.getWidth()))*1,
                    (int) (Math.random() * MyApplication.getContext().getResources().getDisplayMetrics().heightPixels * 0.2)*1,
                    0,
                    10+speedParam,
                    hpParam);
        }
        return null;
    }
}
